package dev.marsh.hunter

import android.text.TextUtils

/**
 * Hunter
 *
 * @author zhaozhe
 * Created on 2018/7/14.
 */
object Hunter {
    private val apps = App.instance.resources.getStringArray(R.array.apps)!!
    private val rules = App.instance.resources.getStringArray(R.array.rule)!!

    fun hunter(pkgName: String): Boolean {
        return apps.contains(pkgName)
    }

    fun filter(text: String?): Boolean {
        if (TextUtils.isEmpty(text)) {
            return true
        }

        val trim = text!!.trim()
        if (TextUtils.isEmpty(trim)) {
            return true
        }

        for (rule in rules) {
            if (rule == trim || trim.contains(rule)) {
                return true
            }
        }

        return false
    }
}